package com.suanfa.dp;

/**
 * 给定数组代表可以跳跃的步数
 */
public class Jump {

    public static void main(String[] args) {
        int[] nums = {3,2,1,0,4};

        System.out.println(jump(nums));
    }

    public static boolean jump(int[] nums){

        int far = 0;
        for(int i = 0; i< nums.length; i++){
            if(i <= far) {
                far = Math.max(far, i + nums[i]);
                if (far >= nums.length - 1) {
                    return true;
                }
            }
        }
        return false;
    }
}
